<?=view('admin.common.header')?>
<?=view('admin.common.nav')?>
<div class="container">
    <div class="row">
        <div class="panel panel-default">
            <div class="panel-heading">
                发布新任务
            </div>
            <div class="panel-body">
                <div class="col-xs-12 col-sm-12">
                    <form id="noticeadd" class="form-horizontal mtop15" method="post">
                        <div class="form-group">
                            <label for="" class="col-sm-2 control-label">装机人员姓名</label>
                            <div class="col-sm-10">
                                <input type="text" value="" name="name" class="form-control" placeholder="--装机人员姓名--" required="required">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="" class="col-sm-2 control-label">联系电话(登录帐号)</label>
                            <div class="col-sm-10">
                                <input type="text" value="" name="phone" class="form-control" placeholder="--联系电话(登录帐号)--" required="required">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="" class="col-sm-2 control-label">登录密码</label>
                            <div class="col-sm-10">
                                <input type="text" value="" name="password" class="form-control" placeholder="--登录密码--" required="required">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="" class="col-sm-2 control-label">负责小区</label>
                            <div class="col-sm-10">
                                <?php if ($plots && count($plots)): ?>
                                <?php foreach ($plots as $val): ?>
                                <label class="col-sm-3">
                                <input type="checkbox" name="plots[]" value="<?=$val->id?>"> <?=$val->name?>　　
                                </label>
                                <?php endforeach; ?>
                                <?php endif; ?>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button class="btn btn-success eveAdd" onclick="return false;">添加装维</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div> 
    </div>
</div>
<script>
    $('.eveAdd').click(function(){
        if ($(this).attr('disabled') ==  'disabled')
            return false;
        if (!(checkNull($("input[name=name]"), "请填写装维人员姓名") && checkNull($("input[name=phone]"), "请填写装维人员联系电话(登录帐号)") && checkNull($("input[name=password]"), "请填写登录密码)"))) {
            return false;
        }
        $(this).attr('disabled', 'disabled');
        $('#noticeadd').ajaxSubmit(function(data){
            layer.msg(data.info);
            if (data.status == 1) {
                window.setTimeout(function(){window.location.reload();}, 2000);
            } else if (data.status == 1) {
                $('.eveAdd').removeAttr('disabled');
            }
        });
    });
    
    function checkNull(elem, msg) {
        if (elem.val() == '') {
            layer.msg(msg);
            elem.focus();
            return false;
        }
        return true;
    }
</script>
<?=view('admin.common.footer')?>